package com.imay.live.view.custom;

import android.content.Context;
import android.graphics.Color;
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;

import com.imay.live.activity.recharge.RechargeActivity;
import com.imay.live.view.BgLineRelativiLayout;
import com.imay.live.R;

/**
 * Created by lzx on 2017/04/17 0017.
 * 支付宝
 */

public class AlipayRechargeView extends BgLineRelativiLayout {
    RechargeActivity rechargeActivity;
    CheckBox iv_check;

    public AlipayRechargeView(RechargeActivity rechargeActivity) {
        super(rechargeActivity);
        init(rechargeActivity);
        this.rechargeActivity = rechargeActivity;
    }

    public void setcheck(boolean isChecked) {
        if (iv_check != null) {
            iv_check.setChecked(isChecked);
        }
    }

    public boolean isChecked() {
        if (iv_check != null) {
           return iv_check.isChecked();
        }
        return false;
    }

    @RequiresApi(api = 21)
    public AlipayRechargeView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init(context);
    }

    void init(Context context) {
        setBackgroundColor(Color.WHITE);
        View view = LayoutInflater.from(context).inflate(R.layout.item_weixinrecharge_layout, this, true);
        iv_check = (CheckBox) view.findViewById(R.id.iv_check);
        iv_check.setChecked(true);
        TextView tv_title = (TextView) view.findViewById(R.id.tv_title);
        tv_title.setText(getResources().getString(R.string.recharge_paytitle));
        TextView tv_content = (TextView) view.findViewById(R.id.tv_content);
        tv_content.setText(getResources().getString(R.string.recharge_zhifubaodes));
        LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        params.height = (int) getResources().getDimension(R.dimen.weixin_height);
        view.setLayoutParams(params);
        setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                iv_check.performClick();
//                iv_check.setChecked(!iv_check.isChecked());
//                rechargeActivity.payCheck(AlipayRechargeView.this, iv_check.isChecked());
            }
        });
        iv_check.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                rechargeActivity.payCheck(AlipayRechargeView.this, isChecked);
            }
        });
    }
}
